package com.bjsxt.controller;

import com.bjsxt.commons.pojo.BaizhanResult;
import com.bjsxt.pojo.TbUser;
import com.bjsxt.service.PassportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author coder_z
 * @date 2023/3/20
 **/
@RestController
public class PassportController {
    @Autowired
    private PassportService passportService;
    @RequestMapping("/user/checkUserInfo/{value}/{flag}")
    public BaizhanResult check(@PathVariable String value, @PathVariable Integer flag){
        return passportService.check(value,flag);
    }
    @RequestMapping("/user/userRegister")
    public BaizhanResult register(TbUser user){
        return passportService.register(user);
    }
    @RequestMapping("/user/userLogin")
    public BaizhanResult login(TbUser user, HttpSession session){
        BaizhanResult result = passportService.login(user);
//        只有登录成功才放入session中
        if(result.getStatus()==200){
            session.setAttribute("loginUser",result.getData());
        }
        return result;
    }
    @RequestMapping("/user/logout")
    public BaizhanResult logout(HttpSession session){
//      销毁session对象
        session.invalidate();
        return BaizhanResult.ok();
    }

}
